package com.waiterxiaoyy.backandroiddesign.Service.impl;

import com.waiterxiaoyy.backandroiddesign.Service.MemberService;
import com.waiterxiaoyy.backandroiddesign.entity.ClassName;
import com.waiterxiaoyy.backandroiddesign.entity.Member;
import com.waiterxiaoyy.backandroiddesign.mapper.MemberMapper;
import com.waiterxiaoyy.backandroiddesign.utils.poi.MemberPoi;
import com.waiterxiaoyy.backandroiddesign.utils.vo.DataVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.io.IOException;
import java.util.List;

/**
 * @author :WaiterXiaoYY
 * @description: TODO
 * @data :2020/12/31 10:41
 */
@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberMapper memberMapper;

    public DataVo saveMember() {
        DataVo dataVo = new DataVo();
        dataVo.setCode(202);
        dataVo.setMsg("保存失败");
        try {
            List<Member> memberList = MemberPoi.saveMember();
            if(memberList.size() > 0) {
                for(Member member : memberList) {
                    memberMapper.saveMember(member);
                }
            }
            dataVo.setCode(200);
            dataVo.setMsg("成功");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return dataVo;
        }
    }

    @Override
    public DataVo getClassName() {
        DataVo dataVo = new DataVo();
        dataVo.setCode(202);
        dataVo.setMsg("获取失败");
        try {
            List<ClassName> classNameList = memberMapper.getClassName();
            dataVo.setData(classNameList);
            dataVo.setCode(200);
            dataVo.setMsg("获取成功");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return dataVo;
        }

    }
}
